package com.electronicmallapiidea;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.electronicmallapiidea.entity.User;
import com.electronicmallapiidea.mapper.UserMapper;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.sql.Wrapper;
import java.util.HashMap;
import java.util.List;

/**
 * 分页查询
 */

@SpringBootTest
public class Demo03_BaseMapper {
    @Autowired
    private UserMapper userMapper;
    Page<User> page = new Page<>(1,10);
    QueryWrapper<User> wrapper = Wrappers.query();

    /**
     * 无条件分页查询
     */
    @Test
    void test1(){
        userMapper.selectPage(page,null);
        //当页数据
        List<User> pageData = page.getRecords();
        pageData.forEach(System.out::println);
    }

    //带条件分页查询

    @Test
    void test2(){
        wrapper.like("username","wrk1");
        userMapper.selectPage(page,wrapper);
        //当页数据
        List<User> pageData = page.getRecords();
        pageData.forEach(System.out::println);
    }

    //以map显示查询分页数据
    @Test
    void test3(){
        Page page = new Page<>(1, 3);
        userMapper.selectMapsPage(page,null);
        List<HashMap<String,Object>> pageData = page.getRecords();
        pageData.forEach(System.out::println);
    }
}
